package com.changgou.order.dao;

import com.changgou.pojo.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;

public interface OrderMapper extends Mapper<Order> {

    /**
     * 根据用户名查询所有订单
     * @param username
     * @return
     */
    @Select("select * from tb_order too,tb_order_item toi where too.id = toi.order_id and username=#{username}"
    )
    List<Map> findByUsername(String username);

    /**
     * 根据用户名查询未付款订单
     * @param username
     * @return
     */
    @Select("select * from tb_order too, tb_order_item toi where too.id = toi.order_id and too.order_status = 0 and username=#{username}")
    List<Map> findUnpaid(@Param("username") String username);

    /**
     * 根据OrderId查询订单详情
     * @param orderId
     */
    @Select("select * from tb_order_item where order_id = #{orderId}")
    Map findOrderId(String orderId);


}
